package com.stone.inventory.core.config;

import com.stone.inventory.core.app.algorithm.StockLevelShardingByPosCodeAlgorithm;
import com.stone.inventory.core.app.algorithm.TransactionShardingByPosCodeAlgorithm;
import com.stone.inventory.core.app.id.StockLevelShardingIdInjector;
import com.stone.inventory.core.app.id.TransactionShardingIdInjector;
import com.stone.inventory.sharding.config.properties.DbShardingProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 库存core 分片自动配置
 *
 * @author Mr_wenpan@163.com 2021/08/16 23:18
 */
@Configuration
@ConditionalOnProperty(prefix = "stone.inv.db", name = {"sharding"}, havingValue = "true")
public class StoneInvCoreShardingAutoConfiguration {
    @Bean
    public StockLevelShardingByPosCodeAlgorithm stockLevelShardingByPosCodeAlgorithm(DbShardingProperty dbShardingProperty) {

        return new StockLevelShardingByPosCodeAlgorithm(dbShardingProperty);
    }

    @Bean
    public TransactionShardingByPosCodeAlgorithm transactionShardingByPosCodeAlgorithm(DbShardingProperty dbShardingProperty) {
        return new TransactionShardingByPosCodeAlgorithm(dbShardingProperty);
    }

    @Bean
    public StockLevelShardingIdInjector stockLevelShardingIdInjector() {

        return new StockLevelShardingIdInjector();
    }

    @Bean
    public TransactionShardingIdInjector transactionShardingIdInjector() {

        return new TransactionShardingIdInjector();
    }
}
